package com.piaodekuai.flight.web;
import java.util.List;

import com.piaodekuai.flight.mapper.TestMapper;
import com.piaodekuai.flight.mapper.UserMapper;
import com.piaodekuai.flight.pojo.Test;
import com.piaodekuai.flight.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;


@Controller
public class TestController {
    @Autowired
    TestMapper testMapper;
    @Autowired
    UserMapper userMapper;
     
    @RequestMapping("/userMapper2")
    public String listCategory1(Model m, HttpServletRequest request) throws Exception {

        String firstName = request.getParameter("firstName");
        System.out.println("firstName="+firstName);

        List<Test> cs=testMapper.findAll();
        List<User> users2 = userMapper.findAll();
        User user = userMapper.selectByPrimaryKey(2);
        for(int i = 0; i<cs.size();i++){
            Test category = cs.get(i);
            System.out.println(category.toString());
        }
        for(int i = 0; i<users2.size();i++){
            User user2= users2.get(i);
            System.out.println(user2.toString());
        }
        System.out.println(user.toString());

        return "Home";
    }


    @RequestMapping("/listCategory")
    public String listCategory(Model m) throws Exception {
        List<Test> cs=testMapper.findAll();

        m.addAttribute("cs", cs);

        return "listCategory";
    }


/*    @RequestMapping("/userMapper")
    public ModelAndView listCategory(ModelAndView mv) throws Exception {
        List<Test> cs=categoryMapper.findAll();
        User user = userMapper.selectByPrimaryKey(2);
        for(int i = 0; i<cs.size();i++){
            Test category = cs.get(i);
            System.out.println(category.toString());
        }
        System.out.println(user.toString());

        mv.setViewName("/userMapper");
        return mv;
    }*/

     
}